<?php
	// Check crossing acess
	if (!defined('RIGHT_ACCESS') || !defined('ROOT_FOLDER'))
	{
		header('Content-Type: text/xml; charset=utf-8');
		echo '<?xml version="1.0"?>';
		echo '<atomtask>';
		echo '<request>error.request.invalid </request>';
		echo '</atomtask>';
		return;
	}	
	class DB
	{
		private static $host = '';
		private static $username = '';
		private static $password = '';
		private static $dtb = '';
		public static function init()
		{
			$info_file = ROOT_FOLDER.'db/info_db.txt';
			if (!file_exists($info_file))
			{
				header('Content-Type: text/xml; charset=utf-8');
				echo '<?xml version="1.0"?>';
				echo '<atomtask>';
				echo '<request>error.request.unknown</request>';
				echo '</atomtask>';
				return;
			}
			// Read db information
			$lines = file($info_file, FILE_IGNORE_NEW_LINES);
			try {
				DB::$host = $lines[0];
				DB::$username = $lines[1];
				DB::$password = $lines[2];
				DB::$dtb = $lines[3];	
			} catch (Exception $e) {
				header('Content-Type: text/xml; charset=utf-8');
				echo '<?xml version="1.0"?>';
				echo '<atomtask>';
				echo '<request>error.request.unknown</request>';
				echo '</atomtask>';
				return;
			}
			mysql_query("SET character_set_results=utf8");
			mb_language('uni');
			mb_internal_encoding('UTF-8');
			mysql_query("set names 'utf8'");
			mysql_query("SET character_set_client=utf8");
			mysql_query("SET character_set_connection=utf8");
		}
		public static function connect()
		{
			try
			{
				mysql_connect(DB::$host, DB::$username, DB::$password);
				mysql_select_db(DB::$dtb);
			}
			catch (Exception $e)
			{
				header('Content-Type: text/xml; charset=utf-8');
				echo '<?xml version="1.0"?>';
				echo '<atomtask>';
				echo '<request>error.request.unknown</request>';
				echo '</atomtask>';
			}
		}
		public static function query($query)
		{
			return mysql_query($query);
		}
	}
	DB::init();
	DB::connect();
?>